const mongoose = require('mongoose')
const Content = require('../constant')
/*

    订单状态
        - 未付款
        - 已付款
        - 已发货
        - 已完成
        - 已取消

    订单
        下单
        付款订单
        取消订单
        查询

    (多个商品, 一个用户, 订单状态: 
        已下单,
        已支付,
        已经发货,
        已收货
    )

    openid
    commodityList: []
    date
    status: ''
    address: {}
    money
    orderNum
*/

const OrderSechema = mongoose.Schema({
    openid: { type: String, require: true },
    commodityList: [],
    date: { type: Date, default: () => new Date() },
    status: { type: String, default: Content.ORDER_STATUS_CREATEAT },
    address: {},
    money: 0,
    isDelete: { type: Boolean, default: false },
    orderNum: { type: String, default: () => {
        return Date.now() + parseInt(Math.random() * 1e5)
    } }
})

const Order = mongoose.model('order', OrderSechema)

module.exports = Order
